import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'i$_c5$_ur$!acs9b0ckx3sl+n82b9_)w4j8m%6w@h$l(o%2#i)'

DEBUG = True

ALLOWED_HOSTS = ['*', '120.0.0.1']

INSTALLED_APPS = [
    'corsheaders',
    'simpleui',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # 用户app
    'operation.base',
    'operation.stats',
    'operation.users',
    'operation.leases',
    'operation.trains',
    'operation.searches',
    'operation.timeline',
    'operation.permissions',

    'operation.projects',
    'operation.projects.infos',
    'operation.projects.datas',
    'operation.projects.checks',
    'operation.projects.equipments',

    'easy_thumbnails',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',

    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_WHITELIST = (
    'http://localhost:3000',
)
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_METHODS = (

    'DELETE',

    'GET',

    'OPTIONS',

    'PATCH',

    'POST',

    'PUT',

    'VIEW',

)

CORS_ALLOW_HEADERS = (

    'accept',

    'XMLHttpRequest',

    'X_FILENAME',

    'accept-encoding',

    'authorization',

    'content-type',

    'dnt',

    'origin',

    'user-agent',

    'x-csrftoken',

    'x-requested-with',

    'Pragma',

    'X-Custom-Header',

)

ROOT_URLCONF = 'settings.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

AUTH_USER_MODEL = "users.User"
WSGI_APPLICATION = 'settings.wsgi.application'

# REST_FRAMEWORK
REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "operation.auth.backends.Token",
    ),
    "DEFAULT_THROTTLE_CLASSES": (
        "operation.base.api.throttling.CommonThrottle",
    ),
    "DEFAULT_THROTTLE_RATES": {
        "user-detail": None,
        "user-update": None,
        "user-read": None,
        "user-write": None,
        "login-fail": None,
        "register-success": None,
        "anon-read": None,
        "anon-write": None,
    },
    "DEFAULT_THROTTLE_WHITELIST": [],
    "DEFAULT_PAGINATION_CLASS": 'operation.base.api.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
}

# Database

DATABASES = {
    'default': {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "operational_master",
        "USER": "postgres",
        "PASSWORD": "bj103126",
        "HOST": "127.0.0.1",
        "PORT": "5432",
    }
}

SIMPLEUI_HOME_INFO = False
SIMPLEUI_CONFIG = {
    'system_keep': False,
    'menus': [
        {
            'name': '项目',
            'app': 'projects',
            'icon': 'fa fa-bars',
            'models': [{
                'name': '团队',
                'url': '/admin/projects/member',
                'icon': 'fa fa-users'
            }, {
                'name': '角色',
                'url': '/admin/projects/role',
                'icon': 'fa fa-tags'
            }, {
                'name': '权限',
                'url': '/admin/projects/permission',
                'icon': 'fa fa-stop'
            }, {
                'name': '项目',
                'url': '/admin/projects/project',
                'icon': 'fa fa-th'
            }, {
                'name': '镜头',
                'url': '/admin/projects/camera',
                'icon': 'fa fa-adjust'
            }, {
                'name': '无人机',
                'url': '/admin/projects/uav',
                'icon': 'fa fa-plane'
            }]
        }, {
            'name': '数据',
            'app': 'Data',
            'icon': 'fa fa-database',
            'models': [{
                'name': "原始数据",
                'url': '/admin/datas/srcdata',
                'icon': 'fa fa-circle'
            }, {
                'name': "标注数据",
                'url': '/admin/datas/markdata',
                'icon': 'fa fa-bookmark'
            }]
        }, {
            'name': '信息',
            'app': 'Info',
            'icon': 'fa fa-info',
            'models': [{
                'name': "信息",
                'url': '/admin/infos/info',
                'icon': 'fa fa-info'
            }]
        }, {
            'name': '缺陷',
            'app': 'Defect',
            'icon': 'fa fa-medkit',
            'models': [{
                'name': "缺陷列表",
                'url': '/admin/detects/defect',
                'icon': 'fa fa-tasks'
            }, {
                'name': "缺陷类型",
                'url': '/admin/detects/defecttype',
                'icon': 'fa fa-bug'
            }]
        }, {
            'name': '用户',
            'app': 'Users',
            'icon': 'fa fa-user',
            'models': [{
                'name': "用户",
                'url': '/admin/users/user',
                'icon': 'fa fa-user'
            }, {
                'name': "消息",
                'url': '/admin/users/usermessage',
                'icon': 'fa fa-comment'
            }]
        }, {
            'name': '训练',
            'app': 'Train',
            'icon': 'fa fa-book',
            'models': [{
                'name': "训练网络",
                'url': '/admin/trains/networkmodel',
                'icon': 'fa fa-table'
            }, {
                'name': "训练模型",
                'url': '/admin/trains/modelinfo',
                'icon': 'fa fa-cubes'
            }, {
                'name': "训练状态",
                'url': '/admin/trains/trainstate',
                'icon': 'fa fa-spinner'
            }]
        }, {
            'name': '设置',
            'app': 'Setting',
            'icon': 'fa fa-cog',
            'models': [{
                'name': "显示设置",
                'url': '/admin/settings/moduledisplay',
                'icon': 'fa fa-eye'
            }]
        }
    ]
}

GRAPPELLI_ADMIN_TITLE = 'SEPD运维数据库'
SIMPLEUI_HOME_TITLE = '百度一下你就知道'

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

ROOT_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

MEDIA_URL = '/media/'
STATIC_URL = '/static/'

PROJECT_PATH = "project"
USER_PATH = "user"

STATICFILES_DIRS = [(os.path.join(BASE_DIR, 'static')), ]
